//
//  CSPopToastView.m
//  CSUIKit
//
//  Created by 网新中研 on 16/8/16.
//  Copyright © 2016年 centralsoft. All rights reserved.
//

#import "CSToastView.h"
#import "Common.h"

#define MARGIN_TOP_BOTTOM 15.0
#define MARGIN_LELF_RIGHT 15.0

@interface CSToastView()
@property (nonatomic, strong) NSString *content;
@end

@implementation CSToastView

+(instancetype)toastViewWithContent:(NSString *)content{
    CSToastView *popToastView = [CSToastView new];
    popToastView.content = content;
    [popToastView layoutView];
    return popToastView;
}


-(void)layoutView{
    
    //label content
    UILabel *label = [UILabel new];
    label.text = self.content;
    label.font = [UIFont systemFontOfSize:15.0];
    label.textColor = [UIColor colorFromHexCode:@"#DAA520"];
    label.textAlignment = NSTextAlignmentLeft;
    label.numberOfLines = 0;
    
    //caculate rect
    CGFloat height = 30.0;
    CGFloat width = [self estimateWith:self.content font:label.font height:height];
    if (width > kWindowW / 4.0 * 3.0) {
        width = kWindowW / 4.0 * 3.0 - 2 * MARGIN_LELF_RIGHT;
    }
    height = [self estimateHeight:self.content font:label.font width:width];
    label.frame = CGRectMake(MARGIN_LELF_RIGHT, MARGIN_TOP_BOTTOM, width, height);
    self.frame = CGRectMake(0, 0, width + 2 * MARGIN_LELF_RIGHT, height + 2 * MARGIN_TOP_BOTTOM);
    
    [self addSubview:label];
    
    self.layer.cornerRadius = 5;
    self.layer.borderColor = COLOR_DEEP_BLUE.CGColor;
    self.layer.borderWidth = 3;
    
    self.backgroundColor = COLOR_PAGE_BACKGROUND;
}

@end
